question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

None equality comparison raises error

See original GitHub issue

the 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
k8s-ci-robotcommented, Jun 25, 2019

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found