Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commons): deduplicate logic to keep behavior consistent [#9][#11] #14

Closed
3 tasks done
rmlibre opened this issue Jul 5, 2024 · 1 comment
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@rmlibre
Copy link
Owner

rmlibre commented Jul 5, 2024

Is this a new bug in aiootp?

  • This affects a supported version of aiootp
  • This isn't a security vulnerability or issue
  • I've searched the existing issues, & I couldn't find one for this bug

Current Behavior

Behavior which is specified by subclasses of Slots in their __setitem__ methods can be bypassed when providing values to the default __init__.

Expected Behavior

The same behavior which is specified in the __setitem__ by a subclass of Slots is applied when using all attribute & value setting interfaces.

Steps To Reproduce

1. With this config:

from aiootp.commons import typed_slots

class Example(typed_slots.FrozenTypedSlots):
    __slots__ = ("attr",)
    slots_types = dict(attr=int)

2. Run:

e = Example(attr="not an int")
# no error

e = Example(attr=2)
e.__init__(attr=4)
# no error, even though frozen

3. See error:

There was no error, but that's the issue.

Relevant log output

No response

Environment

- OS: Ubuntu 20.04
- Python: 3.8.10
- aiootp: 0.23.9

Additional Context

This issue is indicative of a lack of consistency, where logic is duplicated in various methods. Perhaps relying on super() for shared functionalities would be a viable mitigation. This is related to #9 & #11.

@rmlibre rmlibre added the bug Something isn't working label Jul 5, 2024
rmlibre added a commit that referenced this issue Jul 5, 2024
…#14]

The ``__contains__`` logic also needed to be fixed to allow the
simplification in this commit. Checking ``hasattr`` wasn't a limiting
enough condition, as anything in the class dictionary would also
return ``True``. This led to errors when using namespaces as modules,
because they'd take in attribute names like ``__doc__`` which would
proc a ``PermissionError`` in frozen classes.

Resolution related to (#9, #11, #14)
rmlibre added a commit that referenced this issue Jul 6, 2024
#15]

Merge bugfix branch 'fix_inheritance_inconsistencies' into 'main'.

Resolves [#14]
@rmlibre
Copy link
Owner Author

rmlibre commented Jul 6, 2024

Resolved by (26e0026) from [#15]

@rmlibre rmlibre closed this as completed Jul 6, 2024
rmlibre added a commit that referenced this issue Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant