Coder Social home page Coder Social logo

cached_classproperty's Introduction

Hi there, my name is Stanislav Zmiev ๐Ÿ‘‹

telegram mail Linkedln

  • I am a Platform Engineer with an extensive experience in devtools and backend Development
  • I have done a fair share of frontend, mobile, DevOps, and lower level stuff in my spare time
  • I have built numerous open source projects over the years, most of which can be found on my GitHub page
  • My passion is creating and combining development tools to provide programmers with the best possible support while coding. To increase value without needing to increase the team size
  • In my spare time, I contribute to open source and participate in developer meetups and conferences. Over the years I have contributed code to:

... any many smaller projects!

cached_classproperty's People

Contributors

atry avatar ovsyanka83 avatar r4victor avatar zmievsa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cached_classproperty's Issues

Support for Python 3.8 and 3.9

cached_classproperty claims to support Python >= 3.8 but works only on Python >= 3.10 because of the typing union operator used ("|"). The operator should be replaced with Union/Optional to support versions before 3.10.

Related to zmievsa/pydantic-duality#8.

`cached_classproperty` can result in surprising result in inherited classes

Describe the bug
cached_classproperty can result in surprising result in inherited classes

To Reproduce

from cached_classproperty import cached_classproperty

class Superclass:
    @classmethod
    def my_classmethod(cls):
        return ('Superclass.x',)

    @cached_classproperty
    def my_cached_classproperty(cls):
        return cls.my_classmethod()

class Subclass1(Superclass):
    @classmethod
    def my_classmethod(cls):
        return (*super().my_classmethod(), 'Subclass1.x',)

class Subclass2(Superclass):
    @classmethod
    def my_classmethod(cls):
        return (*super().my_classmethod(), 'Subclass2.x',)

class Finalclass(Subclass1, Subclass2):
    @classmethod
    def my_classmethod(cls):
        return (*super().my_classmethod(), 'Finalclass.x',)


print("Subclass2.my_cached_classproperty", Subclass2.my_cached_classproperty)
print("Superclass.my_cached_classproperty", Superclass.my_cached_classproperty)
print("Finalclass.my_cached_classproperty", Finalclass.my_cached_classproperty)
print("Subclass1.my_cached_classproperty", Subclass1.my_cached_classproperty)

print("Superclass.my_classmethod()", Superclass.my_classmethod())
print("Finalclass.my_classmethod()", Finalclass.my_classmethod())
print("Subclass1.my_classmethod()", Subclass1.my_classmethod())
print("Subclass2.my_classmethod()", Subclass2.my_classmethod())

Output:

Subclass2.my_cached_classproperty ('Superclass.x', 'Subclass2.x')
Superclass.my_cached_classproperty ('Superclass.x',)
Finalclass.my_cached_classproperty ('Superclass.x', 'Subclass2.x')
Subclass1.my_cached_classproperty ('Superclass.x',)
Superclass.my_classmethod() ('Superclass.x',)
Finalclass.my_classmethod() ('Superclass.x', 'Subclass2.x', 'Subclass1.x', 'Finalclass.x')
Subclass1.my_classmethod() ('Superclass.x', 'Subclass1.x')
Subclass2.my_classmethod() ('Superclass.x', 'Subclass2.x')

Expected behavior
my_cached_classproperty should return the result same as my_classmethod()

Additional context

$ python --version
Python 3.10.12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.