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 — [pyos][suggestion] Type hints on i/o functions · Issue #435 · python-graphblas/python-graphblas

[pyos][suggestion] Type hints on i/o functions #435

New issue
Copy link
New issue
Copy link
Open
Open
[pyos][suggestion] Type hints on i/o functions#435
Copy link
Labels
discussionDiscussing a topic with no specific actions yetDiscussing a topic with no specific actions yethygieneImprove code quality and reduce maintenance overheadImprove code quality and reduce maintenance overhead

Description

@sneakers-the-rat
sneakers-the-rat
opened on Apr 17, 2023
Issue body actions

Not going to suggest going through and adding type hints to all possible functions, but I think they would be especially useful on the i/o functions since you are traversing libraries and types - this would help the already good interoperability in mixed contexts where people are converting to and from different types, help people know what to expect with static analysis tools. I recognize that you might not have the correct packages imported/installed since they are optionals, but there are a few strategies that might work there -- splitting up the i/o module into a package with submodules where you try and import the necessary packages at the module level and then use string type hints:

something like...

IMPORTED = False
try:
    import networkx as nx
    from networkx.classes.digraph import DiGraph
    IMPORTED = True
except ImportError as e:
    # probably some logging idk
    raise e
    

def to_networkx(m, edge_attribute:str='weight') -> 'DiGraph':
    ...

that's pretty clumsy but hopefully illustrates the idea.

part of: pyOpenSci/software-submission#81

Reacted by Sultan Orazbayev

Activity

  1. eriknw commented on Apr 18, 2023

    @eriknw
    eriknw
    on Apr 18, 2023
    Member
    More actions

    We've been (slowly) exploring type annotations for a while now in #179.

    The argument and return types are already in the numpydoc-style docstrings, so how useful is it to have inline type annotations as well?

    I think the approach we are leaning toward is to add stub files for type annotations. If we do this, does it make sense to add inline annotations to some functions?

    splitting up the i/o module into a package with submodules

    This actually sounds reasonable to me.

    Another approach for doing what you want may be to add e.g.:

    import typing
    
    if typing.TYPE_CHECKING:
        try:
            from networkx import DiGraph, Graph
        except importError:
            ...
    Reacted by Sultan Orazbayev
  2. eriknw
    added
    discussionDiscussing a topic with no specific actions yetDiscussing a topic with no specific actions yet
    hygieneImprove code quality and reduce maintenance overheadImprove code quality and reduce maintenance overhead
    on Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussing a topic with no specific actions yetDiscussing a topic with no specific actions yethygieneImprove code quality and reduce maintenance overheadImprove code quality and reduce maintenance overhead

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — 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.