Skip to content

Instantly share code, notes, and snippets.

@lastforkbender
Created March 28, 2025 04:29
Show Gist options
  • Select an option

  • Save lastforkbender/35e4b0b28136545e55e41bad3b763271 to your computer and use it in GitHub Desktop.

Select an option

Save lastforkbender/35e4b0b28136545e55e41bad3b763271 to your computer and use it in GitHub Desktop.
Shows exact strategy outline for next-gen slots attr classes
global_slots_class_variable = ['_slotsA','_slotsB']
class Nextgen_Slots():
__slots__ = ('name', 'value')
def __init__(self):
self.name = name
self.value = value
#______________________________________________________________________________________
def create_new_dynamic_slots_class(self, class_name, additional_slots=None):
base_slots = self.__slots__
if additional_slots:
combined_slots = base_slots + tuple(additional_slots)
else:
combined_slots = base_slots
def init(self, name, value, extra_attr=None):
Nextgen_Slots.__init__(self, name, value)
if extra_attr is not None:
self.extra_attr = extra_attr
new_class = type(class_name, (Nextgen_Slots,), {
'__slots__': combined_slots,
'show_global_value': lambda self: print(f"Accessing global slots class variable: {global_slots_class_variable}"),})
new_class.__init__ = init
return new_class
#______________________________________________________________________________________
class Nsx1(Nextgen_Slots):
__slots__ = ('_cgr')
def __init__(self):
self._cgr = [None]*10000
#______________________________________________________________________________________
def cgr(self, var_name: str, var_mode=False, var_value=None):
# The only declared slots attr of Nsx1 class is slots _cgr. It is not
# assigned actual variable names, @var_name given is converted to the
# index number of the list @_cgr. Using change creates the variable:
# CHANGE SLOTS VARIABLE: self.cgr('_varA', 1, 'value')
# GET SLOTS VARIABLE: self.cgr('_varB', 1, self.cgr('_varA'))
# RESET SLOTS VARIABLE: self.cgr('_varA', None)
# *Extra precaution should be taken in how your variable(s) are named
# with this single slots cgr map list strategy, whereof entangling a
# duplicate variable name with changes/assigns has no warnings if so
# ..or can be taken advantage of if writing bloch sphere simulations
# when use of custom zip() routines involving this method as matrice
# that other function variables don't have direct observation to all
# in include of on-the-fly dynamic created slots classes shown above
if var_mode:
self._cgr[sum(map(ord, var_name))] = var_value
elif not var_mode:
return self._cgr[sum(map(ord, var_name))]
else:
self._cgr[sum(map(ord, var_name))] = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment