• 4 Posts
  • 30 Comments
Joined 2 years ago
cake
Cake day: June 15th, 2023

help-circle



  • But that mathematical pseudo code has nothing in common with the walrus operator := in Python and Go. They are just the same symbols, but with a totally different meaning and use case. Its an operator designed specifically for programming languages, because that is not applicable to mathematics at all. In mathematics you don’t have an assignment operator a = 69 that cannot be used as part of an expression. Therefore you don’t need a dedicated := that yields an expression that can be used as part of an expression and create a variable if its not already. (Edit: I’m so sick of my stupidness.)


  • Turns out it was introduced in 3.8, released in 2019, so it was much too late to inspire Go

    You are probably right about that. But don’t forget that the operator didn’t made it day one, there was lot of discussion before and probably testing it in the beta releases before. But given how old Golang at that point is, you are right about my take on inspiration. This operator wasn’t a new invention in Python.

    It also has a substantially different meaning than in Go.

    I don’t know if there’s an “official” rationale for the Go syntax, but := is a fairly common (but not ubiquitous) math notation meaning “define the thing on the left to be equal to the expression on the right”, i.e. to distinguish it from the other use of =, i.e. “the expression on the left must be equal to the expression on the right.”

    Does it though? In both cases, Go and Python, the operator will assign a variable a value and also use it as an expression. That is useful in cases like for loops or other cases where you want immediately use the variable content as an expression. This cannot be done with the regular assignment operator a = 69, which itself is not an expression. So in practical terms, its the same in usability for Go and Python. So its doing the same for both languages and has the same differences to the assignment operator. (Edit: Read the reply, I learned something myself. That’s why its important that you don’t blindly teach people like I did.)



  • The := operator is called walrus operator and is inspired by Python I think. It’s declaring a variable and assigning it in one go. map[string] int is defining a map (associative array or also known as dictionary in Python), with string as key type and int as value type. And the following {} is the body of the associative array, meaning empty content.

    I only played a bit with Go and did basic tutorials. I might go back to it at some point, but Zig is much more appealing to me. Go is too simple in the language to me, but on the other side, this is exactly whats appealing.





  • I copied the sub-headings from the document, serving as an overview:

    • Introducing Windows Copilot Runtime to provide a powerful AI platform for developers
    • New experiences built using the Windows Copilot Runtime
    • Windows Copilot Library offers a set of APIs helping developers to accelerate local AI development
    • Introducing Windows Semantic Index that redefines search on Windows. Vector Embeddings API offers the capability for developers to build their own vector store with their app data
    • Windows is the first platform to have a state-of-the-art SLM shipping inbox and Phi Silica is custom built for the NPUs in Copilot+ PCs
    • Developers can bring their own models and scale across breadth of Windows hardware powered by DirectML
    • PyTorch is now natively supported on Windows with DirectML
    • DirectML now supports web apps that can take advantage of silicon to deliver AI experiences powered by WebNN
    • High-performance inferencing on Windows with ONNX Runtime and DirectML
    • New experiences designed to help every developer become more productive on Windows 11
    • Environments in Dev Home help centralize your interactions with all remote environments. Create, manage, launch and configure dev environments in a snap from Dev Home
    • Windows Customization in Dev Home allows developers to customize their device to an ideal state with fewest clicks
    • New Export feature in Dev Home Machine Configuration allows you to quickly create configuration files to share with your teammates, boosting productivity
    • Dev Drive introduces block cloning that will allow developers to perform large file copy operations, instantaneously
    • Sudo for Windows allows developers to run elevated commands right in Terminal
    • New Source code integration in File Explorer allows tracking commit messages and file status directly in File Explorer
    • Continuing to innovate and accelerating development for Windows on Arm
    • Continuing investments in WinUI3 and WPF to help developers build rich, modern Windows applications
    • WinUI 3 and Windows App SDK now support native Maps control and .NET 8
    • Windows 11 theme support makes it easy to modernize the look and feel of your WPF applications
    • Extend Windows apps into 3D space
    • Building for the future of AI on Windows






  • Basically another shell scripting language. But unlike most other languages like Csh or Fish, it can compile back to Bash. At the moment I am bit conflicted, but the thing it can compile back to Bash is what is very interesting. I’ll keep an eye on this. But it makes the produced Bash code a bit less readable than a handwritten one, if that is the end goal.

    curl -s "https://raw.githubusercontent.com/Ph0enixKM/AmberNative/master/setup/install.sh" | $(echo /bin/bash)

    I wish this nonsense of piping a shell script from the internet directly into Bash would stop. It’s a bad idea, because of security concerns. This install.sh script eval and will even run curl itself to download amber and install it from this url

    url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}" … echo “Please make sure that root user can access /opt directory.”;

    And all of this while requiring root access.

    I am not a fan of this kind of distribution and installation. Why not provide a normal manual installation process and link to the projects releases page: https://github.com/Ph0enixKM/Amber/releases BTW its a Rust application. So one could build it with Cargo, for those who have it installed.



  • I think in Python 3.11 and prior overriding new was needed in order to subclass it correctly, because it was buggy until 3.12. This was a workaround, if I remember correctly. I already tried without new and setting self__source, but couldn’t make it work. I was close!

    With your suggestion it works now! I will need to test the app a bit now and if everything looks fine, will update the repository. Did exactly what you said and replaced this part:

    # class File(PosixPath):
    #     def __new__(cls, *args: Any, **kwargs: Any) -> Any:
    #         return cls._load_parts(args).expanduser().resolve()  # type: ignore
    #
    #     def __init__(self, source: str | Path, *args: Any) -> None:
    #         super().__init__()
    #         self.__source = Path(source)
    #
    class File(PosixPath):
        def __init__(self, source: str | Path, *args: Any) -> None:
            self.__source = Path(source)
            super().__init__(Path(source, *args).expanduser().resolve())
    
    

    Thank you for the help and solution!

    Edit: Forgot to answer your question. This could work without subclassing too off course, but doing it this way makes it more clean in my opinion. It’s the natural way to me to extend functionality and use the extended version for the purpose its designed to. It’s not strictly required and I would have done it otherwise too, if this was problematic and not working.


  • From https://github.com/python/cpython/blob/3.12/Lib/pathlib.py

    class PosixPath(Path, PurePosixPath):
        """Path subclass for non-Windows systems.
    
        On a POSIX system, instantiating a Path should return this object.
        """
        __slots__ = ()
    
        if os.name == 'nt':
            def __new__(cls, *args, **kwargs):
                raise NotImplementedError(
                    f"cannot instantiate {cls.__name__!r} on your system")
    

    Which sub classes PurePosixPath, which itself is basically just PurePath with a Posix flavour to it. And Path itself is PurePath as well. Not sure if I should copy paste them here.

    Edit: So I added these to my reply:

    PurePath

        def __new__(cls, *args, **kwargs):
            """Construct a PurePath from one or several strings and or existing
            PurePath objects.  The strings and path objects are combined so as
            to yield a canonicalized path, which is incorporated into the
            new PurePath object.
            """
            if cls is PurePath:
                cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
            return object.__new__(cls)
    
    
        def __init__(self, *args):
            paths = []
            for arg in args:
                if isinstance(arg, PurePath):
                    if arg._flavour is ntpath and self._flavour is posixpath:
                        # GH-103631: Convert separators for backwards compatibility.
                        paths.extend(path.replace('\\', '/') for path in arg._raw_paths)
                    else:
                        paths.extend(arg._raw_paths)
                else:
                    try:
                        path = os.fspath(arg)
                    except TypeError:
                        path = arg
                    if not isinstance(path, str):
                        raise TypeError(
                            "argument should be a str or an os.PathLike "
                            "object where __fspath__ returns a str, "
                            f"not {type(path).__name__!r}")
                    paths.append(path)
            self._raw_paths = paths
    

    Path

    
        def __init__(self, *args, **kwargs):
            if kwargs:
                msg = ("support for supplying keyword arguments to pathlib.PurePath "
                       "is deprecated and scheduled for removal in Python {remove}")
                warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
            super().__init__(*args)
    
        def __new__(cls, *args, **kwargs):
            if cls is Path:
                cls = WindowsPath if os.name == 'nt' else PosixPath
            return object.__new__(cls)