GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - a2435191/python-attribute-access-modifiers: Add C#-like `{get; set;}` syntax to Python attributes.

BranchesTags
Open more actions menu

Latest commit

 

History

10 Commits
10 Commits

Folders and files

NameName
Last commit message
Last commit date
paam
paam
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
setup.py
setup.py
 
 

Repository files navigation

python-attribute-access-modifiers

Tired of typing @property just to make a read-only instance variable? Find yourself wishing for C#'s {get; set;} syntax? Look no further than PAAM, which auto-generates property getters, setter, and deleters for you!

Quickstart

Once installed, just use the overloaded | operator between an instance variable and one of the predefined constants GET, SET, or DEL. Make sure to subclass from PaamBase.

from paam import SET, PaamBase

class Test(PaamBase):
    def __init__(self, a: int):
        self.a = a | GET # write to self.a (not self._a) because PAAM creates setters/getters/deleters *after* __init__ finishes

>>> obj = Test(15)
>>> obj.a
>>> 15
>>> obj.a = 5 # raises AttributeError: can't set attribute

Property access modifiers can also be chained (order doesn't matter):

from paam import SET, GET, DEL, PaamBase

class Test(PaamBase):
    def __init__(self, a: int):
        self.a = a | GET | SET

>>> obj = Test(15)
>>> obj.a
>>> 15
>>> obj.a = 5
>>> obj.a
>>> 5
>>> del obj.a # raises AttributeError: can't delete attribute

Caveats (all planned to be fixed in future release)

  • The type of any variable "annotated" with GET, SET, or DEL is _PropertyAccessModifierBase. This means mypy support and IDE type hinting are most likely broken.
  • No tests
  • Error messages currently only show owner class

About

Add C#-like `{get; set;}` syntax to Python attributes.

pypi.org/project/python-attribute-access-modifiers/

Topics

access-modifiersoop-pythonpython

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.