Get permission to view a parent's list of items

Currently, I have a diagnostic class implemented as a @dataclass in Python. This class includes a method that corresponds to the level of the diagnostic message (e.g., info, warning, error), along with an enumeration named Level:

@dataclass
class Diagnostic:
    #instance variables bc dataclass
    severity: Level
    message: str
    start: Tuple[int, int]
    end: Tuple[int, int]

    class Level(enum.IntEnum):
        info = 0
        error = 1
        warning = 2
        #....

@classmethod
    def create(...)
        #....

@classmethod
    def info(...)
        #....

@classmethod
    def warning(...)
        #....

@classmethod
    def error(...)
        #....

To enhance this setup, I aim to create separate classes for each type of diagnostic message. After some thought, I devised a new structure where Diagnostic_Error, Diagnostic_Info, and Diagnostic_Warning act as subclasses of the Diagnostic class which is no longer a dataclass:

class Diagnostic:
    # instance properties
    __slots__ = ("message", "start", "end")

    def __init__(
        self, message: str, start: Tuple[int, int], end: Tuple[int, int]
    ) -> None:
        self.message = message
        self.start = start
        self.end = end

    class Level(enum.IntEnum):
        info = 0
        error = 1
        warning = 2

        # potentially redundant?
        @classmethod
        def from_docutils(cls, docutils_level: int) -> "Diagnostic.Level":
            level = docutils_level - 1
            level = min(level, cls.warning)
            level = max(level, cls.info)
            return cls(level)


class Diagnostic_Info(Diagnostic):
    severity: Diagnostic.Level = Level.info


class Diagnostic_Warning(Diagnostic):
    severity: Diagnostic.Level = Level.warning


class Diagnostic_Error(Diagnostic):
    severity: Diagnostic.Level = Level.error

However, I encounter an issue where it states Name 'Level' is not defined.

How can I access the parent's enumeration from the child class? Specifically, how do I access the Level enum from Diagnostic_Error, Diagnostic_Info, and Diagnostic_Warning?

Answer №1

It appears that you are utilizing Diagnostic.Level in the type hint, but simply using Level when assigning a value to severity. Both instances involve Level, which is an attribute of Diagnostic.

class Diagnostic_Info(Diagnostic):
    severity: Diagnostic.Level = <b>Diagnostic.</b>Level.info

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to include cms.urls in sitemap.xml for my Django application

I have implemented the following code in my Django project. Within views.py: class MediatorViewSitemap(Sitemap): changefreq = 'monthly' priority = 0.8 def items(self): return Mediator.objects.exclude(photo='') ...

Displaying JSON data on a Django template

As I worked on developing a website, I encountered an issue. The JSON data I am sending from views.py to my template is not displaying any content. data = { "philip": {"age": 20, "salary": 10000}, "jerry": {"age": 27, "salary": 30000} } names ...

Guide on utilizing a single JSON label file for all YOLO-NAS training images

Looking to implement the YOLO object detection Model? I have successfully annotated my images and have them in coco format. I now have a Json file containing label annotations for the train, test, and valid data sets. When defining the model's confi ...

Amazon Web Services P3 underperforms when compared to a local GPU running Keras, TensorFlow, and MobileNet model

Currently, I am fine-tuning a pre-trained MobileNet model using Keras and TensorFlow on my local computer equipped with a GTX980. To speed up the training process, I decided to set up a p3.2xlarge instance on AWS running an Amazon Deep Learning AMI based ...

Python's absence has been noted, thus rendering the script unable to be executed

Today, I encountered an issue while trying to run a Python script: python ./helloworld.py -bash: python: command not found Despite having Python installed on my computer: whereis python python: /usr/bin/python3.6 /usr/bin/python3.6m /usr/lib/python3.6 / ...

The code is stuck in an infinite loop while attempting to convert .jp2 files to .jpg

I need help converting .jp2 files in a specific folder to .jpg format using Python scripting. import os import pyvips #Specifying the directory directory = 'D:\Anaconda\data' # Loop through all files in the directory for filename in ...

There was an issue trying to access the JSON file, as it seems that string indices

I am struggling with accessing items from a nested json file. Can someone provide some guidance? intents = {"intents": [ {"tag": "greeting", "patterns": ["Hi", "Hey", "Is anyone there?", "Hello", "Hay"], "responses": ["Hello", "Hi", "Hi there ...

How to Retrieve Chrome's Download Folder Using ChromeDriver

I’ve been utilizing Selenium ChromeDriver and am running into an issue with identifying the download directory for Chrome in my Python script. The script collects files from a website, but each user may have a different download location set up. Is the ...

Selenium error: Element not found - Element for login cannot be located

Attempting to leverage Selenium for downloading a file from . To access the file, logging in is required. However, encountering difficulty as an error is displayed when trying to fetch the email input field. Below is the code snippet: from selenium import ...

Basic linear regression with a limitation

After developing an algorithm to iterate through 15 variables and generate a basic OLS for each one, I then expanded the algorithm to loop another 11 times. This time, it produced the same 15 OLS regressions, but with the lag of the X variable increasing b ...

The two counter variables within the for loop are failing to meet the condition for equality

Issue Description: For a given array arr[] of size N and two elements x and y, the goal is to use counter variables to determine which element appears more frequently in the array, x or y. If both elements have the same frequency, then return the smaller e ...

Eliminate rows depending on the value within a specified list entry in a column

I need help removing rows from my dataframe based on specific conditions. My dataset groads has the following structure: bridge tunnel x y 262732 F F [4.9703655, 4.9720589] [52.8451222, 52.8450346] 262733 ...

Using Selenium and Python to Select Drop-Down Menus

I have a drop-down menu with the following options: <select name="issuer"> <option selected="selected" value="15">MBBTampereRootCA </option><option value="66222">OMS_CA1 </option><option value="66225">OMS_CA2 </optio ...

Create a function named input_information that receives data entered by the user

Is there a way to create a function named "information" that accepts user input for the following variables: name, birth_year, fav_color, and hometown? This function should return a tuple containing these variables in the specified order. ...

Transferring cookie data between requests in CrawlSpider

My current project involves scraping a bridge website to gather data from recent tournaments. I have previously asked for help on this issue here. Thanks to assistance from @alecxe, the scraper now successfully logs in while rendering JavaScript with Phant ...

Extract dropdown menu options

OBJECTIVE The aim is to explore every possible combination from this website: WHAT I'M SEEKING ADVICE ON I need some guidance on how to proceed with the task. ISSUE AT HAND I am facing a problem where I can retrieve a list of options for the first ...

What is the most efficient method for transferring Flask variables to Vue?

I am currently developing a visualization application using a flask server and vue.js for the front end. Other discussions on this topic explore how to avoid conflicts between vue.js and flask variable syntax, as shown here. In my scenario, I'm inte ...

Having difficulty extracting table data with selenium and beautiful soup

I've hit a wall in trying to extract data from a table on Yahoo's daily fantasy webpage. Despite scouring StackOverflow for solutions, I can't seem to get the desired information. The table either appears empty or the elements within it are ...

Python: parsing comments in a cascading style sheet document

I am currently working on extracting the first comment block from a CSS file. Specifically, I am looking for comments that follow this pattern: /* author : name uri : link etc */ and I want to exclude any other comments present in the file, such as: /* ...

Achieving 5-star ratings on Google through Selenium with Python

I'm attempting to leave a 5-star review for a location on Google Maps. I've successfully written the comment, but I am unable to select the stars. Here is the code snippet I used to submit the comment and give 5 stars: WebDriverWait(driver, 10). ...