connor-makowski / type_enforced

A pure python type enforcer for annotations. Enforce types in python functions and methods.
MIT License
45 stars 2 forks source link

Ability to undecorate the specific class method #26

Closed Ashark closed 8 months ago

Ashark commented 11 months ago

I have decorated the whole class with this:

import type_enforced

@type_enforced.Enforcer
class MyClass():
    def __init__(self):
        ...

    def method1(self):
        ...

    def method2(self):
        ...

This is convenient, because I do not need to add this decorator to each class's method.

But sometimes I want to disable the decoration for the specific method, while still keeping the decoration for all other methods (again, for convenience). For example, it may be useful for false positive detection workarounding.

Is it possible to "undecorate" the specific method? Something like this:

@type_enforced.Enforcer
class MyClass():
    def __init__(self):
        ...

    def method1(self):
        ...

    @type_enforced.Enforcer(disable=True)
    def method2(self):
        ...
connor-makowski commented 10 months ago

This is an interesting thought. In your case, only functions/methods with annotations are enforced. If you remove annotations, then the types are not enforced.

Regarding a negation, this may prove tricky. I like the idea. Let me look into it.

connor-makowski commented 8 months ago

Tagging: https://github.com/connor-makowski/type_enforced/commit/7ba73625f214656586e40dd8fb52a139e771836b

connor-makowski commented 8 months ago

Tagging: https://github.com/connor-makowski/type_enforced/commit/67ecd6c6c1bdfbea9b296c644c2a6aaf49908f8b