None equality comparison raises error
See original GitHub issuethe generated code and its built-in eq comparison raises an error, for example,
import kubernetes
j = kubernetes.client.models.V1Job()
j == None
AttributeErrorTraceback (most recent call last)
<ipython-input-87-70fc4dcff2b7> in <module>()
1 import kubernetes
2 j = kubernetes.client.models.V1Job()
----> 3 j == None
/usr/lib/python2.7/site-packages/kubernetes/client/models/v1_job.pyc in __eq__(self, other)
170 Returns true if both objects are equal
171 """
--> 172 return self.__dict__ == other.__dict__
173
174 def __ne__(self, other):
AttributeError: 'NoneType' object has no attribute '__dict__'
I don’t know if this is an artifact of the swagger implementation, or whether it’s something that can be controlled in the project. I think being able to compare objects to None is a reasonable thing to do and you shouldn’t have to resort to
if type(job) == type(None): # wow. client library overrides equality comparison, badly. Throws with a direct None comparison
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Python None comparison: should I use "is" or - Stack Overflow
Use is when you want to check against an object's identity (e.g. checking to see if var is None ). Use == when...
Read more >Testing equality to None — CodeQL query help documentation
When you compare an object to None , use is rather than == . None is a singleton object, comparing using == invokes...
Read more >Equality comparisons and sameness - JavaScript | MDN
Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared.
Read more >7. Simple statements — Python 3.11.1 documentation
If no expressions are present, raise re-raises the exception that is currently being handled, which is also known as the active exception. If...
Read more >Comparing things to None the wrong way - QuantifiedCode
The statement below uses the equality operator to compare a variable to None . This is not the PEP 8 preferred approach to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mbohlool @ntfrnzn looks like this got fixed https://github.com/swagger-api/swagger-codegen/commit/3236ade09dc659c4d63981573d82d043270da2ef
@fejta-bot: Closing this issue.
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.