Skip to content

hasattr on Language instance attribute raises KeyError #3160

Closed
@jayvdb

Description

hasattr doesnt work correctly, as failure to resolve it should raise AttributeError

>>> from coalib.bearlib.languages.Language import Language
>>> l = Language['C#']
>>> l.extensions
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../coalib/bearlib/languages/Language.py", line 342, in __getattr__
    return self._attributes[item]
KeyError: 'extensions'
>>> hasattr(l, 'extensions')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../coalib/bearlib/languages/Language.py", line 342, in __getattr__
    return self._attributes[item]
KeyError: 'extensions'

To be backwards compatible, a new exception class is needed, that subclasses both KeyError and AttributeError.

This was released in 0.9, so fixing this is still a minor bug. Nobody will be relying on this bad behaviour in production yet.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions