Demo

Filename: example_1.py

from typing import Any, Optional


def my_func(arg1: Optional[Any] = None) -> int:
    # This is a very long line that should normally fail, but we want it to
    # be present as is.
    my_very_very_very_long_variable_name_just_to_show_a_very_long_line_of_x_characters = (
        1
    )
    print(
        my_very_very_very_long_variable_name_just_to_show_a_very_long_line_of_x_characters
    )
    a = (
        arg1
        or my_very_very_very_long_variable_name_just_to_show_a_very_long_line_of_x_characters
    )
    print(a)

    return "0"


class ThirdPartyLibrary:
    @staticmethod
    def get_dynamic_object() -> Any:
        # Returns an object whose type is not known at compile time
        return "a string"  # In reality, this could be any type


# Usage of the third-party library
obj = ThirdPartyLibrary.get_dynamic_object()

# Attempt to use the object as a string, even though its type is 'Any'
length = len(obj)

# Deliberately long line to violate PEP 8 line length rule, suppressed with
print(f"The length of the object, a dynamically typed one, is just {length}")

# --- Additional tests for ignore markers ---

# Test noqa
print("Test noqa")

# Test type checkers
print("Test type: ignore")

# Test coverage and similar inline markers:
print("Test no cover")
print("Test no branch")

# Formatting control markers:

print("Test fmt skip block - unformatted text")

print("This line should be formatted normally.")

# YAPF markers:
print("Test yapf disable")
print("Test yapf enable")

# Pylint markers:
print("Test pylint disable")
print("Test pylint enable")

# Flake8 marker:
print("Test flake8 noqa")

# IDE-specific suppression marker:
print("Test noinspection directive")

# Security allowlisting markers:
print("Test allowlist secret")
print("Test NOSONAR")

See the full example here